<%= turbo_stream_from [:projects, current_account] %>

<div class="overflow-auto">
  <table class="table mt-2 rounded-box" id="shop_table" data-component="table">
    <thead>
      <tr>
        <th>
          <span class="text-sm font-medium text-base-content/80">Name</span>
        </th>
        <th>
          <span class="text-sm font-medium text-base-content/80">Status</span>
        </th>
        <th>
          <span class="text-sm font-medium text-base-content/80">Cluster Name</span>
        </th>
        <th>
          <span class="text-sm font-medium text-base-content/80">Last Deployment</span>
        </th>
        <th>
          <span class="text-sm font-medium text-base-content/80">Commit</span>
        </th>
      </tr>
    </thead>
    <tbody>
      <% projects.order(created_at: :desc).each do |project| %>
        <tr class="cursor-pointer hover:bg-base-200/40" id="<%= dom_id(project, :index) %>">
          <td>
            <div class="font-medium"><%= link_to project.name, project_deployments_path(project), class: "text-inherit hover:underline" %></div>
          </td>
          <td>
            <%= render "projects/status", project: project %>
          </td>
          <td>
            <div><%= project.cluster&.name %></div>
          </td>
          <td>
            <% if project.last_deployment_at %>
              <div>
                <div role="tooltip" data-tip="<%= project.last_deployment_at.strftime("%B %d, %Y %I:%M %p") %>" class="tooltip">
                  <div class="text-sm"><%= time_ago(project.last_deployment_at) %></div>
                </div>
                <div class="text-xs italic"><%= project.last_deployment.build.commit_message.truncate(50) %></div>
              </div>
            <% else %>
              <div class="text-sm">Never</div>
            <% end %>
          </td>
          <td>
            <% if project.last_build %>
              <div>
                <%= link_to (commit_sha = project.last_build.commit_sha)[0..6], 
                  "https://github.com/#{project.repository_url}/commit/#{commit_sha}",
                    class: "underline",
                    target: "_blank",
                    rel: "noopener noreferrer" %>
              </div>
            <% end %>
          </td>
          <td>
            <div class="inline-flex w-fit">
              <%= link_to project_deployments_path(project) do %>
                <button aria-label="Edit project" class="btn btn-square btn-ghost btn-sm">
                  <iconify-icon icon="lucide:pencil" height="15" class="text-base-content/70"></iconify-icon>
                </button>
              <% end %>
            </div>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>
                   
